package pl.selvin.android.ListSyncSample.provider;

import pl.selvin.android.ListSyncSample.Constants;
import pl.selvin.android.syncframework.SetupInterface;
import pl.selvin.android.syncframework.content.BaseContentProvider;
import pl.selvin.android.syncframework.content.ContentHelper;
import android.database.Cursor;
import android.net.Uri;

public class ListProvider extends BaseContentProvider {
	// we don't need implementation ... base class do everything on it's own
	// this is just class which we are pointing in xml files as Provider
	// since one day i'll move BaseContentProvider to library

	private static ContentHelper helperInstance;

	public static final synchronized ContentHelper getHelper() {
		if (helperInstance == null)
			helperInstance = ContentHelper.getInstance(Setup.class);
		return helperInstance;
	}

	public ListProvider(){
		super(getHelper());
	}

	@Override
	public Cursor query(Uri uri, String[] projection, String selection,
			String[] selectionArgs, String sortOrder) {
		try {
			// delay for testing
			// Thread.sleep(2000);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return super
				.query(uri, projection, selection, selectionArgs, sortOrder);
	}

	public static class Setup implements SetupInterface {

		@Override
		public String getServiceUrl() {
			return Constants.SERVICE_URI;
		}

		@Override
		public String getAuthority() {
			return Constants.AUTHORITY;
		}

		@Override
		public Class<?> getDatabaseClass() {
			return Database.class;
		}

		@Override
		public String getDatabaseName() {
			return "listdb";
		}

		@Override
		public int getDatabaseVersion() {
			return 17;
		}
	}

}
